package com.ebring.shareEducation.controller;

import com.ebring.shareEducation.bean.Transaction;
import com.ebring.shareEducation.service.TransationService;
import com.ebring.shareEducation.utils.RspMsg;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@CrossOrigin(origins = "http://wangliang.vipgz1.idcfengye.com", maxAge = 3600)
@Api(value = "场外交易管理" ,tags = {"场外交易管理"})
public class TransactionController {

    @Autowired
    private TransationService transationService;


    /**
     * 根据订单ID查找订单
     *
     * @param id 订单ID
     * @return
     */
    @GetMapping("/transation/selectById")
    @ApiOperation(value="根据订单ID查找订单", notes="根据订单ID查找订单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "id", value = "订单ID", required = true, dataType = "String"),
    })
    public RspMsg<Transaction> selectTradeById(String id) {
        return transationService.selectTradeById(id);
    }

    /**
     * 查找所有订单
     *
     * @param
     * @return
     */
    @GetMapping("/transation/selecttrade")
    @ApiOperation(value="查找所有订单", notes="查找所有订单")
    public RspMsg<Transaction> selectTradefind() {
        return transationService.selectTradefind();
    }








    /**
     * 法币订单管理模块模糊时查询

     * @param transaction
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/transation/findTrade")
    @ApiOperation(value="法币订单管理模块模糊时查询", notes="法币订单管理模块模糊时查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "Traderecords", value = "法币订单对象", required = true, dataType = "Traderecords"),
            @ApiImplicitParam(paramType="query",name = "pageNum", value = "页数", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType="query",name = "pageSize", value = "总页数", required = true, dataType = "Integer"),
    })
    public RspMsg<List<Transaction>> findTrade(Transaction transaction, Integer pageNum, Integer pageSize) {

        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        return transationService.findTrade(transaction);
    }

    /**
     * 场外交易买入
     */
    @PostMapping("/transation/insert")
    @ApiOperation(value="场外交易买入", notes="场外交易买入")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userid", value = "买入方用户id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userids", value = "买入方用户id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "amount", value = "数量", required = true, dataType = "BigDecimal"),
            @ApiImplicitParam(name = "bankid", value = "银行id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bid", value = "币种id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "交易类型", required = true, dataType = "Integer"),
    })
    public RspMsg<Transaction> insertRole(String userid,String userids,BigDecimal amount, String bankid, String bid,Integer type) {
        return transationService.insertTrade(userid,userids,amount,bankid,bid,type);

    }


    /**
     * 确认到账
     */
    @PostMapping("/transation/updatetran")
    @ApiOperation(value="确认到账", notes="确认到账")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "交易id", required = true, dataType = "String")
    })
    public RspMsg<Transaction> updatetran(String id) {
        return transationService.updateTran(id);
    }

    /**
     * 未打款
     */
    @PostMapping("/transation/updatetrans")
    @ApiOperation(value="未打款", notes="未打款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "交易id", required = true, dataType = "String")
    })
    public RspMsg<Transaction> updatetrans(String id) {
        return transationService.updateTrans(id);
    }

}
